# **********************************************************************
# docrevs
#
# This script uses the DOCZ utilities to determine if there are any
# revisions, introductions, or fixes in the libraries.  The documentation
# is generated, deposited in $DAT, and a notice is mailed to a mailing
# list and posted to a local newsgroup.
#
# This script should be run early in the day once a week.
# **********************************************************************

# defines DOCZ symbols and modifies PATH (if required)
. /usr2/common/bin/syms

# DOCZ administrator on this system
MANAGER=todd
# mailing list
MAILIST=$DAT/docs.lis
# reference date file
REFDATE=$DAT/docrevs.dat
# temporary announcement file
ANNOUNCE=/usr/tmp/docrevs.not
# temporary error report for administrator
ERRORS=/usr/tmp/docrevs.err
# this is the name for the file containing the revision notices
NOTICE="$DAT/REV.`calcdate | sed 's/\///g'`"
# this is the name for the file containing the revision summaries
SUMMARY="$DAT/SUM.`calcdate | sed 's/\///g'`"
# this is the name of the ASCII Transport File for help
TRANSPORT="$DAT/dochelp.txt"
# list of libraries
LIBLIST="CSUB UTIL DOCZ CURSLIB TOOLZ DOCLIB"

rm $SUMMARY
rm $NOTICE
rm $ERRORS
rm $TRANSPORT

# **********************************************************************
# this function produces the basic notices for any DOCZ library
# Modification notices are not performed (doc /m)
do_doc()
{
   LIBNAME=`echo $1 | tr "[a-z]" "[A-Z]"`    # make upper case
	echo Producing $LIBNAME Revisions
	doc $LIBNAME -r=`cat $REFDATE` -s 2>>$ERRORS
	if [ $? -eq 0 ]
	then
	   cat $LIBNAME.DOC >> $NOTICE
	   rm $LIBNAME.DOC
		echo $LIBNAME Revision Summary >> $ANNOUNCE
		cat $LIBNAME.REV >> $ANNOUNCE
		echo $LIBNAME Revision Summary >> $SUMMARY
		cat $LIBNAME.REV >> $SUMMARY
		rm $LIBNAME.REV
	   echo "> $LIBNAME Revision Notice = $NOTICE" >> $ANNOUNCE
	else
	   echo "No $LIBNAME revisions since `cat $REFDATE`" >> $ANNOUNCE
	fi
	
	echo Producing $LIBNAME Introductions
	doc $LIBNAME -i=`cat $REFDATE` -s 2>>$ERRORS
	if [ $? -eq 0 ]
	then
	   cat $LIBNAME.DOC >> $NOTICE
	   rm $LIBNAME.DOC
		echo $LIBNAME Introduction Summary >> $ANNOUNCE
		cat $LIBNAME.INT >> $ANNOUNCE
		echo $LIBNAME Introduction Summary >> $SUMMARY
		cat $LIBNAME.INT >> $SUMMARY
		rm $LIBNAME.INT
	   echo "> $LIBNAME Introduction Notice = $NOTICE" >> $ANNOUNCE
	else
	   echo "No $LIBNAME introductions since `cat $REFDATE`" >> $ANNOUNCE
	fi
	
	echo Producing $LIBNAME Fixes
	doc $LIBNAME -f=`cat $REFDATE` -s 2>>$ERRORS
	if [ $? -eq 0 ]
	then
	   cat $LIBNAME.DOC >> $NOTICE
	   rm $LIBNAME.DOC
		echo $LIBNAME Fix Summary >> $ANNOUNCE
		cat $LIBNAME.FIX >> $ANNOUNCE
		echo $LIBNAME Fix Summary >> $SUMMARY
		cat $LIBNAME.FIX >> $SUMMARY
		rm $LIBNAME.FIX
	   echo "> $LIBNAME Fix Notice = $NOTICE" >> $ANNOUNCE
	else
	   echo "No $LIBNAME fixes since `cat $REFDATE`" >> $ANNOUNCE
	fi
	if [ -r $LIBNAME.ERR ]
	then
	   mail $MANAGER <$LIBNAME.ERR
	   rm $LIBNAME.ERR
	fi
	
}

# real work begins here
# **********************************************************************
# create the announcement file
if [ ! -r $REFDATE ]             # new file
then
   calcdate > $REFDATE
fi
echo "`calcdate` Revision, Fix, and Introduction Notices since `cat $REFDATE`\n" > $ANNOUNCE
echo Producing REVISION NOTICES `cat $REFDATE`

# **********************************************************************
# add library names here

for i in $LIBLIST
do
	do_doc $i
done

# **********************************************************************
# distribute the announcement, if present
if [ -r $NOTICE ]
then
   echo "\nNote:  $NOTICE is print-image for HP-Laser-Jet" >> $ANNOUNCE
fi

# **********************************************************************
# post the notice locally to News
if [ -r $ANNOUNCE ]
then
/usr3/news/lib/inews \
   -t 'Library Revision Notice' \
   -n local.post  \
   -d local \
   -h \
   -r emory\!toolz\!todd \
   < $ANNOUNCE

# **********************************************************************
# mail the notice to a mailing list (this requires the 'mailist' script)
	mailist "Periodic Library Revision Notice" $MAILIST $ANNOUNCE

# **********************************************************************
# mail the notice to the MANAGER
	mailx -s "WEEKLY: Periodic Library Revision Notice" $MANAGER <$ANNOUNCE
	rm $ANNOUNCE
fi

# **********************************************************************
# update the reference date
calcdate -o=$REFDATE  # update last revision date
echo Reference date updated to `cat $REFDATE`

# **********************************************************************
# mail the errors to the MANAGER
if [ -f $ERRORS ]
then
   mailx -s "WEEKLY: DOCZ errors" $MANAGER <$ERRORS
   rm $ERRORS
fi

# **********************************************************************
# verify the presence of all files
docxlu -v=$ERRORS
mailx -s "WEEKLY: DOCZ source verification" $MANAGER <$ERRORS
rm $ERRORS

# **********************************************************************
# search for rogue files
for i in $LIBLIST
do
	docxlu $i -c=/usr/tmp/$i.z
	echo $i >>$ERRORS
	cat /usr/tmp/$i.z >>$ERRORS
	rm /usr/tmp/$i.z
done
mailx -s "WEEKLY: DOCZ search for rogue files" $MANAGER <$ERRORS
rm $ERRORS

# **********************************************************************
# re-build on-line help library (this is a killer with version control!)
dochbld -h -ao=$TRANSPORT

#
